package com.mes.web.controller.biz;

import com.github.pagehelper.PageInfo;
import com.mes.biz.domain.BizOrder;
import com.mes.biz.domain.BizOrderInstaller;
import com.mes.biz.domain.vo.OrderDeliveryVo;
import com.mes.biz.domain.vo.OrderInstallVo;
import com.mes.biz.service.BizOrderInstallerService;
import com.mes.common.annotation.Log;
import com.mes.common.core.controller.BaseController;
import com.mes.common.core.domain.R;
import com.mes.common.core.page.PageDomain;
import com.mes.common.enums.BusinessType;
import com.mes.common.utils.poi.ExcelUtil;
import com.mes.framework.cache.DictUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 销售单安装人员Controller
 * @author hwg
 * @email hwg
 * @date 2023-05-15
 */
@RestController
@RequestMapping("/biz/bizOrderInstaller")
public class BizOrderInstallerController extends BaseController {

    @Autowired
    private BizOrderInstallerService bizOrderInstallerService;

    /**
     * 查询销售单安装人员列表
     */
    @PreAuthorize("@ss.hasPermi('biz:bizOrderInstaller:list')")
    @GetMapping("/list")
    public R<PageInfo> list(BizOrderInstaller bizOrderInstaller, HttpServletRequest request, HttpServletResponse response) {
        bizOrderInstaller.setPage(new PageDomain(request, response));
        return R.data(bizOrderInstallerService.findPage(bizOrderInstaller));
    }

    /**
     * 获取销售单安装人员详细信息
     */
    @PreAuthorize("@ss.hasPermi('biz:bizOrderInstaller:query')")
    @GetMapping(value = "/{id}")
    public R<BizOrderInstaller> detail(@PathVariable("id") String id) {
        return R.data(bizOrderInstallerService.get(id));
    }

    /**
     * 新增销售单安装人员
     */
    @PreAuthorize("@ss.hasPermi('biz:bizOrderInstaller:add')")
    @Log(title = "销售单安装人员", businessType = BusinessType.INSERT)
    @PostMapping
    public R add(@RequestBody BizOrder bizOrder) {
        return R.status(bizOrderInstallerService.saveBatch(bizOrder));
    }

    /**
     * 修改销售单安装人员
     */
    @PreAuthorize("@ss.hasPermi('biz:bizOrderInstaller:edit')")
    @Log(title = "销售单安装人员", businessType = BusinessType.UPDATE)
    @PutMapping
    public R edit(@RequestBody @Validated BizOrderInstaller bizOrderInstaller) {
        return R.status(bizOrderInstallerService.save(bizOrderInstaller));
    }

    /**
     * 删除销售单安装人员
     */
    @PreAuthorize("@ss.hasPermi('biz:bizOrderInstaller:remove')")
    @Log(title = "销售单安装人员", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R remove(@PathVariable String[] ids) {
        return R.status(bizOrderInstallerService.deleteBizOrderInstallerByIds(ids));
    }


    /**
     * 导出销售单安装人员列表
     */
    @PreAuthorize("@ss.hasPermi('biz:bizOrderInstaller:export')")
    @Log(title = "销售单安装人员", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public R export(BizOrderInstaller bizOrderInstaller) {
        List<BizOrderInstaller> list = bizOrderInstallerService.findList(bizOrderInstaller);
        ExcelUtil<BizOrderInstaller> util = new ExcelUtil<BizOrderInstaller>(BizOrderInstaller.class);
        return util.exportExcel(list, "销售单安装人员数据");
    }

    /**
     * 根据字典类型查询字典数据信息等其他自定义信息
     */
    @GetMapping(value = "/getInitData/{dictTypes}")
    public R getInitData(@PathVariable String dictTypes) {
        Map<String, Object> dataMap = new HashMap<String, Object>();
        dataMap.putAll(DictUtils.getMultiDictList(dictTypes));
        return R.data(dataMap);
    }

    @Log(title = "销售单安装人员", businessType = BusinessType.UPDATE)
    @PostMapping("/updateStatus")
    public R updateStatus(@RequestBody BizOrderInstaller bizOrderInstaller) {
        return R.status(bizOrderInstallerService.updateStatus(bizOrderInstaller));
    }

    /**
     * 查询配送统计
     */
    @GetMapping("/listDeliveryStat")
    public R<PageInfo> listDeliveryStat(BizOrderInstaller bizOrderInstaller, HttpServletRequest request, HttpServletResponse response) {
        bizOrderInstaller.setPage(new PageDomain(request, response));
        PageInfo<OrderDeliveryVo> page = bizOrderInstallerService.listDeliveryStatPage(bizOrderInstaller);
        return R.data(page);
    }

    /**
     * 打印配送统计
     */
    @GetMapping("/printDeliveryStat")
    public void printDeliveryStat(BizOrderInstaller bizOrderInstaller, HttpServletRequest request, HttpServletResponse response) {
        bizOrderInstaller.setPage(new PageDomain(request, response));
        List<OrderDeliveryVo> list = bizOrderInstallerService.listDeliveryStat(bizOrderInstaller);
        ExcelUtil<OrderDeliveryVo> util = new ExcelUtil<>(OrderDeliveryVo.class);
        util.printEasyExcel(response,list, "配送统计表", OrderDeliveryVo.class);
    }

    /**
     * 查询安装统计
     */
    @GetMapping("/listInstallStat")
    public R<PageInfo> listInstallStat(BizOrderInstaller bizOrderInstaller, HttpServletRequest request, HttpServletResponse response) {
        bizOrderInstaller.setPage(new PageDomain(request, response));
        PageInfo<OrderInstallVo> page = bizOrderInstallerService.listInstallStatPage(bizOrderInstaller);
        return R.data(page);
    }

    /**
     * 打印安装统计
     */
    @GetMapping("/printInstallStat")
    public void printInstallStat(BizOrderInstaller bizOrderInstaller, HttpServletRequest request, HttpServletResponse response) {
        bizOrderInstaller.setPage(new PageDomain(request, response));
        List<OrderInstallVo> list = bizOrderInstallerService.listInstallStat(bizOrderInstaller);
        ExcelUtil<OrderInstallVo> util = new ExcelUtil<>(OrderInstallVo.class);
        util.printEasyExcel(response,list, "安装统计表", OrderInstallVo.class);
    }

}
